#coding:utf-8
from PIL import ImageGrab
from PIL import Image
from matplotlib import pyplot
from pytesseract import image_to_string
import pyautogui
from PIL import ImageFilter
import cv2
import numpy as np

lat_top_left = (1252, 1017)
lat_down_right = (1337, 1036)
log_top_left = (1415, 1018)
log_down_right = (1507, 1036)

#screenshot = ImageGrab.grab()
screenshot = pyautogui.screenshot()
lat_img = screenshot.crop((lat_top_left[0], lat_top_left[1], lat_down_right[0], lat_down_right[1]))
log_img = screenshot.crop((log_top_left[0], log_top_left[1], log_down_right[0], log_down_right[1]))

#lat_img = lat_img.filter(ImageFilter.EDGE_ENHANCE)
#log_img = log_img.filter(ImageFilter.EDGE_ENHANCE)

lat_img = cv2.bilateralFilter(np.array(lat_img), 3, 50, 20)
log_img = cv2.bilateralFilter(np.array(log_img), 3, 50, 20)

cv2.imwrite('lat_img.jpg', lat_img)
cv2.imwrite('log_img.jpg', log_img)
#pyplot.subplot(1,2,1)
#pyplot.imshow(lat_img)
#pyplot.subplot(1,2,2)
#pyplot.imshow(log_img)
#pyplot.show()

#lat = image_to_string(lat_img)
#log = image_to_string(log_img)

#print lat + ',' + log

